import Vue from 'vue'
import vuex from 'vuex'
Vue.use(vuex)

export default new vuex.Store({
  state: {
    uid: -1,
    token: '',
    username: '',
    role: {
      rolename: '',
      permissions: []
    },
    siderBarShow: true,
    asyncRouterLoad: false,
    showRouterMap: []
  },
  mutations: {
    SET_UID: (state, uid) => {
      state.uid = uid
    },
    SET_TOKEN: (state, token) => {
      state.token = token
    },
    SET_USERNAME: (state, username) => {
      state.username = username
    },
    SET_ROLE: (state, role) => {
      state.role.rolename = role.rolename
      state.role.permissions = state.role.permissions.concat(role.permissions)
    },
    SET_SIDERBARSHOW: (state, siderBarShow) => {
      state.siderBarShow = siderBarShow
    },
    CLEAR_ROLE: (state) => {
      state.role.rolename = ''
      state.role.permissions = []
    },
    SET_SHOWROUTERMAP: (state, showRouterMap) => {
      state.showRouterMap = state.showRouterMap.concat(showRouterMap)
    },
    CLEAR_SHOWROUTERMAP: (state) => {
      state.showRouterMap = []
    },
    SET_ASYNCROUTERLOAD: (state, asyncRouterLoad) => {
      state.asyncRouterLoad = asyncRouterLoad
    },
    CLEAR_ALL: (state) => {
      state.uid = -1
      state.token = ''
      state.username = ''
      state.role = {
        rolename: '',
        permissions: []
      }
      state.siderBarShow = true
      state.asyncRouterLoad = false
      state.showRouterMap = []
    }
  },
  actions: {
  }
})
